package com.ch.sys.filter;

import javax.servlet.http.HttpServletRequest;

import com.ch.sys.common.Constants;
import com.ch.sys.model.Employee;

public class SessionUtils {
	
	private final static ThreadLocal<Employee> user = new ThreadLocal<Employee>();
	
	static public void set(Employee employee){
		user.set(employee);
	}
	
	static public void set(HttpServletRequest request, Employee employee){
		request.getSession().setAttribute(Constants.LOGIN_APP_USER, employee); 
		user.set(employee);
	}
	
	static public Employee get(){
		return user.get();
	}
	
	static public Employee get(HttpServletRequest request) {
		Employee employee = (Employee)request.getSession().getAttribute(Constants.LOGIN_APP_USER);
		SessionUtils.set(request, employee);
		
		return employee;
	}
	
	static void remove(){
		user.remove();
	}
	
	static public void clear(HttpServletRequest request){
		request.getSession().removeAttribute(Constants.LOGIN_APP_USER);
		user.remove();
	}
}
